<template>
  <el-cascader
    :value="value"
    :options="curOptions"
    @input="$emit('input', $event)"
    v-on="$listeners"
    v-bind="$attrs"
  ></el-cascader>
</template>

<script>
export default {
  name: 'v-cascader',
  props: {
    value: null,
    options: {
      type: null,
    },
  },
  data() {
    return {
      curOptions: [],
    };
  },
  methods: {
    getOptions() {
      const { options } = this;

      if (typeof options === 'function') {
        const promise = new Promise(resolve => {
          options(resolve);
        });
        promise.then(data => {
          this.curOptions = data;
        });
      } else {
        this.curOptions = options;
      }
    },

    setOptions(options) {
      this.curOptions = options;
    },
  },

  created() {
    this.getOptions();
  },
};
</script>

<style lang="scss" scoped></style>
